﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace LiteQuery.Controls
{
    public partial class DataPanel : UserControl
    {
        Entities.DataSql data;
        public Entities.DataSql DataSql
        {
            get { return data; }
            set { data = value; }
        }

        public DataTable DataSource {
            get { return dgvData.DataSource as DataTable; }
            set {
                dgvData.DataSource = value;
                dgvData.Refresh();

                lblInfo.Text = string.Format("当前查询结果共 {0} 条记录",dgvData.Rows.Count);
            }
        }


        public DataPanel()
        {
            InitializeComponent();
        }

        public DataPanel(Entities.DataSql d)
        {
            InitializeComponent();
            this.DataSql = d;
        }

        private void dgvData_DataSourceChanged(object sender, EventArgs e)
        {

        }

        private void dgvData_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            
        }

        private void dgvData_CellValidated(object sender, DataGridViewCellEventArgs e)
        {
           
        }

        private void dgvData_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
        {
            if (dgvData.Columns[e.ColumnIndex].ValueType == typeof(Int64) 
                && Common.DateHelper.TimestampToDate((long)dgvData.Rows[e.RowIndex].Cells[e.ColumnIndex].Value)> new System.DateTime(1971, 1, 1))
                e.Value = LiteQuery.Common.DateHelper.TimestampToDate((long)dgvData.Rows[e.RowIndex].Cells[e.ColumnIndex].Value);
        }
    }
}
